package com.situ.wms.controller;

import com.situ.wms.entity.Manager;
import com.situ.wms.impl.UserServiceImpl;
import com.situ.wms.service.UserService;
import com.situ.wms.util.BaseController;
import com.situ.wms.util.DBUtil;
import com.situ.wms.vo.ResultVO;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/newpassword")
public class NewPassword extends BaseController {
        UserService service =new UserServiceImpl();
        ResultVO vo = new ResultVO();
        public ResultVO update(HttpServletRequest request,String old_password,String new_password){
            System.out.println(old_password+","+new_password);
                String username =(String) request.getSession().getAttribute("currentManager");
                Manager manager = new Manager();
                manager=service.selectByUserName(username);
                String oldpassword= DBUtil.md5(old_password);
                String newpassword=DBUtil.md5(new_password);

                if(!(oldpassword.equals(manager.getPassword()))){
                    System.out.println("错了！");
                      vo.setCode(1);
                      vo.setMsg("旧密码错误！");
                        return vo;
                }else{
                 manager.setPassword(newpassword);
                 service.update(manager);
                 return vo;
                }
        }
}
